import { setLineStyle } from "@/utils/setStyle"
// 没有标注的高德矢量地图
const gaode_scl1 = new ol.layer.Tile({
  title: 'gaode_noMarker',
  source: new ol.source.XYZ({
    url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&scl=2&x={x}&y={y}&z={z}',
    wrapX: false,
    crossOrigin: 'Anonymous' // 允许跨域
  })
})
// 没有标注的高德矢量地图
const gaode_scl2 = new ol.layer.Tile({
  title: 'gaode_noMarker',
  source: new ol.source.XYZ({
    url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&scl=2&x={x}&y={y}&z={z}',
    wrapX: false,
    crossOrigin: 'Anonymous'
  }),
  opacity: 0
})
// 有标注的高德矢量地图
const gaode_vector = new ol.layer.Tile({
  title: 'gaode_vector',
  source: new ol.source.XYZ({
    url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
    wrapX: false,
    crossOrigin: 'Anonymous'
  })
})
// 有标注的高德影像图
var gaode_image = new ol.layer.Tile({
  title: 'gaode_image',
  source: new ol.source.XYZ({
    url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=6&x={x}&y={y}&z={z}',
    wrapX: false,
    crossOrigin: 'Anonymous'
  }),
  opacity: 0
})
// mapGIS发布的地图服务
const docLayer = new Zondy.Map.Doc('', 'guanggu3', {
  // 第二个参数是发布的服务名称；ip 和 port 默认值就是这俩
  // ip: "localhost",
  // port: 6163
  zIndex: 100,
  title: '新中地',
  crossOrigin: 'Anonymous'
})

// 通过查询拿到事件图层 并转换为 ol.feature，然后创建热力图
const service = {
  name: 'guanggu3',
  layerId: 4
}
var heatMapLayer = new ol.layer.Heatmap({
  title: 'heatmp',
  source: new ol.source.Vector({
    features: []
  }),
  crossOrigin: 'Anonymous',
  opacity: 0,
  /* 模糊 */
  blur: 5,
  /* 半径 */
  radius: 8,
  zIndex: 1000
})
Query.queryByLayerId({
  service,
  success: (res) => {
    heatMapLayer.getSource().addFeatures(res)
  }
})

// flow图层
const serviceFlow = {
  name: 'guanggu3',
  layerId: 1
}
let flowSource = new ol.source.Vector({

})
let flowLayer = new ol.layer.Vector({
  title:'flow',
  source:flowSource,
  style: function (feature) {
      let flow = feature.values_.values_.车流量;
      let color = null;
      if (flow >= 2000) {
          color = "rgb(255, 0, 0)"
      } else if(flow >= 1500){
        color = "rgb(170, 85, 0)"
      }
       else if(flow >= 1000){
        color = "rgb(85, 191, 0)"
      }
      else {
          color = "rgb(0, 255, 0)"
      }
      return setLineStyle({
          color
      })
  },
  opacity: 0,
  zIndex:1000,
})
Query.queryByLayerId({
  service:serviceFlow,
  success: (res) => {
    flowLayer.getSource().addFeatures(res)
  }
})
// 画布图层
// 创建矩形画布——用于拉框删除
let BoxDrawSource = new ol.source.Vector({})
let BoxDrawLayer = new ol.layer.Vector({
  source: BoxDrawSource,
  zIndex: 2000
})

// 创建点画布——用于存放兴趣点
let DrawSource = new ol.source.Vector({})
let DrawLayer = new ol.layer.Vector({
  source: DrawSource,
  zIndex: 2000
})
// 创建点画布——用于暂存事件点
let EventSource = new ol.source.Vector({})
let EventLayer = new ol.layer.Vector({
  source: EventSource,
  zIndex: 2000
})
// 创建点画布——用于高亮事件要素
let HighlightSource = new ol.source.Vector({})
let HighlightLayer = new ol.layer.Vector({
  source: HighlightSource,
  zIndex: 2000
})

// 用于测量
let MeasuringSource = new ol.source.Vector({})
let MeasuringLayer = new ol.layer.Vector({
  source: MeasuringSource,
  zIndex: 2000
})
export {
  gaode_scl1,
  gaode_scl2,
  gaode_vector,
  gaode_image,
  docLayer,
  heatMapLayer,
  DrawLayer,
  DrawSource,
  BoxDrawLayer,
  BoxDrawSource,
  MeasuringSource,
  MeasuringLayer,
  flowLayer,
  flowSource,
  EventSource,
  EventLayer,
  HighlightLayer
}
